package org.example.com.zwh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.com.zwh.entity.Product;

import java.util.List;
import java.util.Map;

@Mapper
public interface ProductStockMapper extends BaseMapper<Product> {
    @Update("UPDATE t_product SET stock = stock - #{stock} WHERE id = #{productId}")
    int updateStock( int stock,  Long productId);

    /**
     * 更新库存
     * @param stock
     * @param productId
     * @return
     */
    @Update("UPDATE t_product SET stock = #{stock} WHERE id = #{productId}")
    int updateStockNow( int stock,  Long productId);
    /***
     * 查询所有库存
     * @return
     */
    @Select("select * from t_product")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "product_name"),
            @Result(property = "price", column = "price"),
            @Result(property = "stock", column = "stock"),
            @Result(property = "description", column = "description"),
            @Result(property = "createTime", column = "create_time"),            // 映射到实体类的 createTime 属性
            @Result(property = "updateTime", column = "update_time"),            // 映射到实体类的 updateTime 属性
            @Result(property = "deleted", column = "deleted")                    // 映射到实体类的 deleted 属性
    })
    List<Product> getAllStocks();

}
